import {createStore} from 'redux'
import {Types} from '../types/types'



interface StateInter{
    list:Types[]
}

let reducer:any = (state:StateInter = {list:[]},action:any) => {
    switch (action.type) {
        case 'INIT_DATA':
            return {list:[...action.list]};
        case 'CHANGE_HOT':{
            // type t_id 习惯
            let index = state.list.findIndex(item => item.type === action.cType);
            let t_index = state.list[index].children.findIndex(t => t.t_id === action.t_id);
            let target =  state.list[index].children[t_index];
            target.habit = action.hobit;
            state.list[index].children[t_index] = {...target};
            return {list:[...state.list]}
        }
        default:
            return state;
    }
}

let store = createStore(reducer)

export default store

